package com.zy.service;

import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.zy.web.bean.MyUserDTO;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @program: shopping153_cloud
 * @description:
 * @author: zy
 * @create: 2025-08-31 10:05
 */
@Component
@Log
public class JmsMessageConsumer {

    @Autowired
    private VelocityTemplateService velocityTemplateService;
    @Autowired
    private MailService mailService;

    @Value(
            "${MAIL_FROM:1069595532@qq.com}"
    )
    private String mailFrom;   //邮件的发送方，这里指定为  中转邮箱.


    /**
     * 接收队列名为  userLogin的新消息，然后处理
     * @param message
     */
    @JmsListener(destination = "userLogin")
    public void receiveMessage(String message) {
       log.info("Received message: " + message);
       Gson gson=new Gson();
       MyUserDTO myUserDTO=gson.fromJson(   message, MyUserDTO.class);
       log.info("myUserDTO:"+myUserDTO.toString());

       String emailInfo=velocityTemplateService.userLoginSuccessInfo(myUserDTO);
       log.info("待发送的邮件内容:"+emailInfo);
       mailService.send( myUserDTO.getEmail(),mailFrom,"用户登录成功",emailInfo);


    }
}
